package com.mh.www.mh_frame.view.widget;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mh.www.mh_frame.R;


/**
 * 进度条工具
 * 样式 1 2 3
 * Created by think on 2017/6/19.
 */

public class CustomProgressDialog {
    private static int[] iconStyles = {R.drawable.ic_progress_style1, R.drawable.ic_progress_style2,
            R.drawable.ic_progress_style3, R.drawable.ic_progress_style4};
    private static ProgressDialog progressDialog;
    public static final int theme_ultimate = 0;
    public static final int theme_dot = 1;
    public static final int theme_line = 2;
    public static final int theme_arc = 3;

    public static void showSuccinctProgress(Context context, String message, int theme, boolean isCanceledOnTouchOutside, boolean isCancelable) {
        progressDialog = new ProgressDialog(context, R.style.succinctProgressDialog);
        progressDialog.setCancelable(isCancelable);
        progressDialog.setCanceledOnTouchOutside(isCanceledOnTouchOutside);
        // 加载自定义的ProgressDialog
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        View view = LayoutInflater.from(context).inflate(
                R.layout.custom_progress_dialog_content, null);
        ImageView mProgressIcon = (ImageView) view
                .findViewById(R.id.progress_icon);
        // 设置样式
        mProgressIcon.setImageResource(iconStyles[theme]);
        TextView mProgressMessage = (TextView) view
                .findViewById(R.id.progress_message);
        // 设置内容
        mProgressMessage.setText(message);
        new AnimationUtils();
        // 设置动画
        Animation jumpAnimation = AnimationUtils.loadAnimation(context,
                R.anim.succinct_animation);
        mProgressIcon.startAnimation(jumpAnimation);
        // 显示
        progressDialog.show();
        // 必须先显示，在设置自定义的View
        progressDialog.setContentView(view, params);

    }

    /**
     * @return true即现实中，false为不在显示
     */
    public static boolean isShowing() {

        return progressDialog != null && progressDialog.isShowing();

    }

    /**
     * 取消Dialog
     */
    public static void dismiss() {

        if (isShowing()) {

            progressDialog.dismiss();
        }

    }


}





